/**
 * 〈一句话功能简述〉<br>
 * 〈〉
 *
 * @author 13754
 * @create 2023/11/29
 * @since 1.0.0
 */
package com.mengniu.commerce.collect.third.request;

import com.alibaba.fastjson.JSONObject;
import com.mengniu.commerce.collect.model.member.QueryMemberParam;
import com.mengniu.commerce.collect.third.WeiMengApi;
import com.mengniu.commerce.collect.third.response.member.MemberInfoResponse;
import com.mengniu.commerce.collect.third.response.member.MemberResponse;
import com.mengniu.commerce.collect.util.RestTemplateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 微盟会员数据请求
 * @author 13754
 * @Date 2023/11/29 11:55
 * @Version 1.0.0
 */
@Service
public class IWeiMengMemberRequest {

    private static String baseUrl ="https://dopen.weimob.com";

    private static String vid ="6001451595805";
    private static String cursorId ="2313-1701313288.082-saas-w1-487-23960966744";

    @Autowired
    RestTemplateUtil restTemplateUtil;

    /**
     * 分页查询会员列表 queryMemberParam
     * @param
     * @return
     */
    public MemberResponse getMemberList(QueryMemberParam queryMemberParam,String token){
        String url =baseUrl+ WeiMengApi.WM_CRM_LIST;
        JSONObject js = new JSONObject();
        js.put("pageNum",queryMemberParam.getPageNum());
        js.put("pageSize",queryMemberParam.getPageSize());
        js.put("vid",vid);
        //类型包括：1-集团；2-品牌；3-区域；4-部门；5-商场；6-楼层；10-门店；11-网点；100-自提点
        js.put("vidType",1);
        List<String> list = new ArrayList<>();
        //微盟Id
        list.add("wid");
        //手机号
        list.add("phone");
        js.put("fields",list);
        js.put("isReturnPageResult",1);
        String result = restTemplateUtil.doPost(js, url,token);
        return  JSONObject.parseObject(result,MemberResponse.class);
    }

    /**
     * 查询会员详情
     * @param widList,resultType
     * @return
     */
    public MemberInfoResponse getMemberInfoById(List<String> widList,List<String> resultType, String token){
        String url =baseUrl+ WeiMengApi.WM_MEMBER_INFO;
        JSONObject js = new JSONObject();
        js.put("vid",vid);
        js.put("widList",widList);
        js.put("resultType",resultType);
        String result = restTemplateUtil.doPost(js, url,token);
        return  JSONObject.parseObject(result, MemberInfoResponse.class);
    }

}
